class_name HealthBar
extends Control


@onready var progress_bar: ProgressBar = $ProgressBar
@onready var label: Label = $Label


@export var background_color: Color
@export var fill_color: Color


var _value: int
var _max_value: int


func _ready():
	_setup_progress_bar_color()



func _setup_progress_bar_color():
	var background: StyleBoxFlat = progress_bar.get_theme_stylebox("background").duplicate()
	background.bg_color = background_color
	var fill: StyleBoxFlat = progress_bar.get_theme_stylebox("fill").duplicate()
	fill.bg_color = fill_color

	progress_bar.add_theme_stylebox_override("background", background)
	progress_bar.add_theme_stylebox_override("fill", fill)



func set_value(value: int, max_value: int):
	_value = value
	_max_value = max_value
	progress_bar.value = remap(float(value), 0.0, float(max_value), progress_bar.min_value, progress_bar.max_value)
	label.text = str(value)
